package com.tzxx.spider.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * @author Created by tzxx
 * @since : 2019/7/19.
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Result<T> {
    @Builder.Default
    private String message = HttpStatus.OK.name();
    @Builder.Default
    private Boolean success = true;
    private T data;
    @Builder.Default
    private int code = HttpStatus.OK.value();

    public static Result ok(){
        return new Result();
    }

    public static Result ok(String msg){
        return Result.builder().message(msg).build();
    }

    public static <T> Result ok(String msg,T data){
        return Result.builder().data(data).message(msg).build();
    }

    public static Result fail(){
        return Result.builder().message("fail").code(HttpStatus.INTERNAL_SERVER_ERROR.value()).build();
    }

    public static Result fail(String msg){
        return Result.builder().message(msg).code(HttpStatus.INTERNAL_SERVER_ERROR.value()).build();
    }

}
